package com.ruoyi.system.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.system.api.domain.SysSerial;
import com.ruoyi.system.service.ISysSerialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 流水号配置Controller
 *
 * @author ruoyi
 * @date 2023-04-14
 */
@Api(tags = "流水号配置")
@RestController
@RequestMapping("/serial")
public class SysSerialController extends BaseController {
    @Autowired
    private ISysSerialService sysSerialService;

    /**
     * 查询流水号配置列表
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询流水号配置列表", response = SysSerial.class)
    public TableDataInfo list(SysSerial sysSerial) {
        startPage();
        List<SysSerial> list = sysSerialService.selectSysSerialList(sysSerial);
        return getDataTable(list);
    }

    @GetMapping("/serialList")
    @ApiOperation(value = "查询流水号配置列表", response = SysSerial.class)
    public AjaxResult serialList(SysSerial sysSerial) {
        List<SysSerial> list = sysSerialService.selectSysSerialList(sysSerial);
        return success(list);
    }

    /**
     * 导出流水号配置列表
     */
    @Log(title = "流水号配置", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ApiOperation(value = "导出流水号配置列表")
    public void export(HttpServletResponse response, SysSerial sysSerial) {
        List<SysSerial> list = sysSerialService.selectSysSerialList(sysSerial);
        ExcelUtil<SysSerial> util = new ExcelUtil<SysSerial>(SysSerial.class);
        util.exportExcel(response, list, "流水号配置数据");
    }

    /**
     * 获取流水号配置详细信息
     */
    @GetMapping(value = "/{serialId}")
    @ApiOperation(value = "获取流水号配置详细信息", response = SysSerial.class)
    public AjaxResult getInfo(@ApiParam(value = "配置id", required = true) @PathVariable("serialId") Long serialId) {
        return success(sysSerialService.selectSysSerialBySerialId(serialId));
    }

    /**
     * 新增流水号配置
     */
    @Log(title = "新增流水号配置", businessType = BusinessType.INSERT)
    @PostMapping
    @ApiOperation("新增流水号配置")
    public AjaxResult add(@RequestBody SysSerial sysSerial) {
        return toAjax(sysSerialService.insertSysSerial(sysSerial));
    }

    /**
     * 删除流水号配置
     */
    @Log(title = "删除流水号配置", businessType = BusinessType.DELETE)
    @DeleteMapping("/delete/{serialIds}")
    @ApiOperation("删除流水号配置")
    public AjaxResult remove(@ApiParam(value = "配置id", required = true) @PathVariable Long[] serialIds) {
        return toAjax(sysSerialService.deleteSysSerialBySerialIds(serialIds));
    }

    /**
     * 创建不同机构相同的数据
     */
    @Log(title = "创建不同机构相同的数据", businessType = BusinessType.INSERT)
    @GetMapping("/create")
    @ApiOperation("创建不同机构相同的数据")
    public AjaxResult updateSerial() {
        return toAjax(sysSerialService.updateSerial());
    }
}
